﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO_HealthInsurance;

namespace DAO_HealthInsurance
{
  public  class DAOPolicyApproval:ConnectDatabase
    {
        public SqlCommand Cmd;
        public DTOPolicyApprovalDetails objPoApp;
        public DataTable ListPolicyApproval()
        {
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("ListPolicyApproval", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyApprovalDetails");
                da.Fill(dt);
                CloseConnect();
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public int InsertPolicyApproval(DTOPolicyApprovalDetails objPoApp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("InsertPolicyApproval", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoApp.PolicyId;
                Cmd.Parameters.Add("@RequestId", SqlDbType.Int).Value = objPoApp.RequestId;
                Cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = objPoApp.ApprovalDate;
                Cmd.Parameters.Add("@Amount", SqlDbType.Float).Value = objPoApp.ApprovalAmount;
                Cmd.Parameters.Add("@Status", SqlDbType.Char,3).Value = objPoApp.ApprovalStatus;
                Cmd.Parameters.Add("@Reason", SqlDbType.VarChar, 50).Value = objPoApp.ApprovalReason;

                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;
        }

        public int DeletePolicyApproval(DTOPolicyApprovalDetails objPoApp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("DeletePolicyApproval", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoApp.PolicyId;
                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }
        public int UpdatePolicyApproval(DTOPolicyApprovalDetails objPoApp)
        {
            int Result = 0;
            try
            {
                OpenConnect();
                Cmd = new SqlCommand("UpdatePolicyApprovalInfo", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoApp.PolicyId;
                Cmd.Parameters.Add("@RequestId", SqlDbType.Int).Value = objPoApp.RequestId;
                Cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = objPoApp.ApprovalDate;
                Cmd.Parameters.Add("@Amount", SqlDbType.Float).Value = objPoApp.ApprovalAmount;
                Cmd.Parameters.Add("@Status", SqlDbType.Char, 3).Value = objPoApp.ApprovalStatus;
                Cmd.Parameters.Add("@Reason", SqlDbType.VarChar, 50).Value = objPoApp.ApprovalReason;

                Result = Cmd.ExecuteNonQuery();
                CloseConnect();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return Result;

        }

        public DataTable GetPolicyApprovalById(DTOPolicyApprovalDetails objPoApp)
        {
            try
            {
                Cmd = new SqlCommand("GetPolicyApprovalById", Conn);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.Add("@PolicyId", SqlDbType.Int).Value = objPoApp.PolicyId;
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable("PolicyApprovalDetails");
                da.Fill(dt);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
    }
}
